package com.multi.thread.chapter04.demo09;

import java.util.concurrent.locks.ReentrantLock;

public class TestQueueThread {
	
	private ReentrantLock lock = new ReentrantLock();
	
	public void waitMethod() {
		try {
			lock.lock();
			Thread.sleep(Integer.MAX_VALUE);
		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally {
			lock.unlock();
		}
	}
	
	public static void main(String[] args) throws InterruptedException {
		final TestQueueThread service = new TestQueueThread();
		Runnable run = new Runnable() {
			@Override
			public void run() {
				service.waitMethod();
			}
		};
		Thread a = new Thread(run);
		a.start();
		Thread.sleep(500);
		Thread b = new Thread(run);
		b.start();
		Thread.sleep(500);
		
		System.out.println(service.lock.hasQueuedThread(a));
		System.out.println(service.lock.hasQueuedThread(b));
		System.out.println(service.lock.hasQueuedThreads());
	}

}
